//
//  Rank_PeopleInfoController.m
//  YLProject
//
//  Created by 张伯林 on 2018/1/28.
//  Copyright © 2018年 WY. All rights reserved.
//

#import "Rank_PeopleInfoController.h"
#import "PowerfulBannerView.h"
#import "Rank_PeopleInfoBottomView.h"
#import "Owner_ChatViewController.h"
#import "Rank_PeopleInfoHeaderCell.h"
#import "Rank_PeopleInfoIntroductCell.h"
#import "Rank_PeopleInfoPhotoCell.h"
#import "Rank_PeopleInfoMarkCell.h"
#import "UIImageView+WebCache.h"
#import "Rank_PeopleInfoNumberView.h"
#import "Rank_ReceiveGiftListController.h"
#import "YLSheetView.h"
#import "Rank_BeatListController.h"
@interface Rank_PeopleInfoController ()<UITableViewDelegate,UITableViewDataSource,YLSheetViewProtocol,Rank_PeopleInfoPhotoCellProtocol>
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *dataSource;
@property (nonatomic,strong) PowerfulBannerView *bannerView;
@property(nonatomic,strong) Rank_PeopleInfoBottomView *bottomView;
@property(nonatomic,strong)Rank_PeopleInfoNumberView *numberView;
@end

@implementation Rank_PeopleInfoController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blackColor];
    AdjustsScrollViewInsetNever(self, self.tableView)
    [self setNavBarButton];
    [self.view addSubview:self.tableView];
    self.tableView.tableHeaderView = self.bannerView;
    
    //添加底部view
    [self.view addSubview:self.bottomView];
    
    //给tableHeaderView添加假数据
    self.bannerView.items = @[@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1517597777865&di=056f11898384670c3209087204d7deec&imgtype=0&src=http%3A%2F%2Fimage.tianjimedia.com%2FuploadImages%2F2015%2F205%2F55%2F33S7N14FX488_1000x500.jpg",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1517597822298&di=a2ef9ea1dd2c67cedb163e54acb08266&imgtype=0&src=http%3A%2F%2Fdesk.fd.zol-img.com.cn%2Ft_s960x600c5%2Fg3%2FM0A%2F02%2F02%2FCg-4V1RO-E6IY-PjADCaKk14ji4AAQl2QNXwsEAMJpC577.jpg",@"https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1161830198,2814060686&fm=27&gp=0.jpg"];
    self.numberView.numberText = [NSString stringWithFormat:@"1/%ld", self.bannerView.items.count];
    [self.bannerView reloadData];
}
-(void)setNavBarButton{
    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    rightButton.frame = CGRectMake(0, 5,34,34);
    [rightButton setBackgroundImage:[UIImage imageNamed:@"排行_highlight"] forState:UIControlStateNormal];
    [[rightButton  rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        NSLog(@"排行右按钮");
        YLSheetView *sheetView = [YLSheetView initWithDataSource:@[@"加入黑名单",@"举报该用户",@"取消"]];
        sheetView.delegate = self;
        [sheetView showSheetView:self];
    }];
    self.navigationItem.rightBarButtonItems = @[[[UIBarButtonItem alloc]initWithCustomView:rightButton]];
}
#pragma mark -- 弹框代理方法
-(void)sheetView:(YLSheetView *)sheetView currentSheetViewType:(YLSheetViewType)type didSelectedIndex:(NSInteger)index{
    if (index == 0) {  //加入黑名单
        YLLog(@"............加入黑名单");
    }else if(index == 1){ //举报此人
        YLLog(@"............举报此人");
    }
}
#pragma mark ---tableView代理方法
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 8;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
//-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//    return 60;
//}
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 10;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return nil;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section == 0){
        Rank_PeopleInfoHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([Rank_PeopleInfoHeaderCell class])];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else if (indexPath.section == 7){
        Rank_PeopleInfoIntroductCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([Rank_PeopleInfoIntroductCell class])];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else if (indexPath.section == 3 || indexPath.section == 4 || indexPath.section == 5 || indexPath.section == 6)
    {
        Rank_PeopleInfoPhotoCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([Rank_PeopleInfoPhotoCell class])];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.delegate = self;
        [cell initWithModel:nil index:indexPath.section];
        return cell;
    }else if (indexPath.section == 1 || indexPath.section == 2){
        Rank_PeopleInfoMarkCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([Rank_PeopleInfoMarkCell class])];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell initWithModel:nil index:indexPath.section];
        return cell;
    }
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class])];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
#pragma mark -- Rank_PeopleInfoPhotoCellProtocol
-(void)didSelectList:(Rank_PeopleInfoPhotoType)type{
    switch (type) {
        case Rank_PeopleInfoPhotoGift:
        {
            [self jumpReceiveGiftList:nil];
        }
            break;
        case Rank_PeopleInfoPhotoBeat:
        {
            Rank_BeatListController *beat = [[Rank_BeatListController alloc]init];
            [self.navigationController pushViewController:beat animated:YES];
        }
            break;
        case Rank_PeopleInfoPhotoPrivate:
        {
            
        }
            break;
        case Rank_PeopleInfoPhotoVideo:
        {
            
        }
            break;
        default:
            break;
    }
    
}
-(void)disSelectDetail:(Rank_PeopleInfoPhotoType)type index:(NSInteger)index{
    switch (type) {
        case Rank_PeopleInfoPhotoGift:
        {
            [self jumpReceiveGiftList:nil];
        }
            break;
        case Rank_PeopleInfoPhotoBeat:
        {
            
        }
            break;
        case Rank_PeopleInfoPhotoPrivate:
        {
            
        }
            break;
        case Rank_PeopleInfoPhotoVideo:
        {
            
        }
            break;
        default:
            break;
    }
}
//跳转收到礼物列表
-(void)jumpReceiveGiftList:(NSString *)userId{
    Rank_ReceiveGiftListController *giftList = [[Rank_ReceiveGiftListController alloc]init];
    [self.navigationController pushViewController:giftList animated:YES];
}

#pragma mark ---懒加载---
//tableHeaderView头部banner
-(PowerfulBannerView *)bannerView{
    if (!_bannerView) {
        CGFloat height = 250 * YL_KEY;
        _bannerView = [[PowerfulBannerView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width, height)];
//        UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, self.bannerView.frame.size.height - 30 * YL_KEY, Screen_Width, 15.0f * YL_KEY)];
//        pageControl.userInteractionEnabled = NO;
        _bannerView.pageControl = nil;
        _bannerView.autoLooping = YES;
        _bannerView.clipsToBounds = true;
        _bannerView.backgroundColor = [UIColor clearColor];
//        [_bannerView addSubview:pageControl];
        _bannerView.bannerItemConfigurationBlock = ^UIView *(PowerfulBannerView *banner, NSString *item, UIView *reusableView) {
            //这个给每个banner元素添加控件
            UIImageView *imageView = (UIImageView *)reusableView;
            if (imageView == nil) {
                imageView = [[UIImageView alloc]initWithFrame:CGRectZero];
            }
            [imageView sd_setImageWithURL:[NSURL URLWithString:item] placeholderImage:[UIImage imageNamed:@"排行_highlight"]];
            return imageView;
        };
        _bannerView.bannerDidSelectBlock = ^(PowerfulBannerView *banner, NSInteger index) {
            //这里处理banner每个相对于的touch事件
            NSLog(@"%ld",index);
        };
        _bannerView.bannerIndexChangeBlock = ^(PowerfulBannerView *banner, NSInteger fromIndex, NSInteger toIndex) {
            self.numberView.numberText = [NSString stringWithFormat:@"%ld/%ld",toIndex + 1,_bannerView.items.count];
        };
        [_bannerView addSubview:self.numberView];
    }
    return _bannerView;
}
-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, Screen_Height - (STATUS_BAR_HEIGHT + 44) - 45 * YL_KEY - YLSafeAreaBottomHeight) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.showsVerticalScrollIndicator = NO;
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass([UITableViewCell class])];
        [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass(Rank_PeopleInfoHeaderCell.class) bundle:nil] forCellReuseIdentifier:NSStringFromClass(Rank_PeopleInfoHeaderCell.class)];
        [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass(Rank_PeopleInfoIntroductCell.class) bundle:nil] forCellReuseIdentifier:NSStringFromClass(Rank_PeopleInfoIntroductCell.class)];
        [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass(Rank_PeopleInfoPhotoCell.class) bundle:nil] forCellReuseIdentifier:NSStringFromClass(Rank_PeopleInfoPhotoCell.class)];
        [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass(Rank_PeopleInfoMarkCell.class) bundle:nil] forCellReuseIdentifier:NSStringFromClass(Rank_PeopleInfoMarkCell.class)];
        _tableView.tableFooterView = [UIView new];
        _tableView.backgroundColor = kHEXCOLOR(@"f4f5f7");
    }
    return _tableView;
}
-(Rank_PeopleInfoBottomView *)bottomView{
    if (!_bottomView) {
        _bottomView = [[Rank_PeopleInfoBottomView alloc]initWithFrame:CGRectMake(0, Screen_Height - 44 - STATUS_BAR_HEIGHT - 45 * YL_KEY - YLSafeAreaBottomHeight, Screen_Width, 50 * YL_KEY)];
        _bottomView.touchBlock = ^(Rank_PeopleInfoBottomType type) {
            NSLog(@"%ld",(long)type);
            switch (type) {
                case Rank_PeopleInfoBottomPrivateChat: //私聊
                {
                    Owner_ChatViewController *conversationVC = [[Owner_ChatViewController alloc]init];
                    conversationVC.conversationType = ConversationType_PRIVATE;
                    if(IS_TEST){
                        conversationVC.targetId = @"yl_20180201101023_01";
                    }else{
                        conversationVC.targetId = @"yl_20180201101023";
                    }
                    conversationVC.title = @"想显示的会话标题";
                    [self.navigationController pushViewController:conversationVC animated:YES];
                }
                    break;
                case Rank_PeopleInfoBottomFollow: //关注
                    break;
                case Rank_PeopleInfoBottomVideoChat: //视频聊
                    break;
                default:
                    break;
            }
        };
    }
    return _bottomView;
}
-(Rank_PeopleInfoNumberView *)numberView{
    if (!_numberView) {
        _numberView = [[Rank_PeopleInfoNumberView alloc]initWithFrame:CGRectMake(Screen_Width - 40 * YL_KEY, 250 * YL_KEY - 45 * YL_KEY, 40 * YL_KEY, 30 * YL_KEY)];
        _numberView.block = ^(CGSize size) {
            _numberView.frame = CGRectMake(Screen_Width - size.width - 15 * YL_KEY, 250 * YL_KEY - 15 * YL_KEY - size.height, size.width, size.height);
        };
    }
    return _numberView;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
